import { useState } from 'react';
import { PaginationResponse } from '@datorama/akita';

import { makeFacade, AudiencesFacade } from '@/facade/audienceEntityFacade';
import { useObservable } from '@/utils/rxHelpers';
import { AudienceItem } from '@/models/response/roomRsp';

export type AudiencesHookTuple = [AudiencesFacade, PaginationResponse<AudienceItem>];

//需要在页面用到的变量都在这里hook，主要用于简化页面调用逻辑和代码
export function useAudiencesFacade(roomId: string): AudiencesHookTuple {
  const [audiencesFacade] = useState(() => makeFacade(roomId)); //默认返回访问过的房间列表

  const [pagination] = useObservable(audiencesFacade.pagination$, {} as PaginationResponse<AudienceItem>);

  return [audiencesFacade, pagination];
}
